/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

/**
 *
 * @author Max
 */
import au.com.bytecode.opencsv.CSVReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import model.TabellenEintrag;

public class CSVLoader {

    private CSVReader csvr;
    private String file;
    private ArrayList<TabellenEintrag> liste;
    
    public CSVLoader (String file) {
        this.file = file;
    }
    
    public ArrayList<TabellenEintrag> getListe() {
        readCSV();
        return liste;
    }

    public void readCSV() {
        liste = new ArrayList<>();

        try {
            csvr = new CSVReader(new FileReader(file));
        } catch (FileNotFoundException e) {
            System.out.println(e.getMessage());
        }
        if (csvr != null) {
            String[] nextLine;
            try {
                while ((nextLine = csvr.readNext()) != null) {
                    TabellenEintrag tabellenEintrag = new TabellenEintrag(nextLine);
                    liste.add(tabellenEintrag);
                }
                csvr.close();
            } catch (IOException e) {
            }

        }

    }

}
